package com.uni.bgController;

import com.uni.config.FastDFSClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;

@Data
public class BaseController {

    @Value("${http://106.13.225.125:90}")
    private String IMG_SERVER_URL;




    public String upload(MultipartFile file){
        try {
            // 接受上传的文件
            // 取扩展名
            String originalFilename = file.getOriginalFilename();
            // 获取扩展名
            String substring = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);

            FastDFSClient client = new FastDFSClient();
            String url = client.uploadFile(file.getBytes(), substring);
            url = IMG_SERVER_URL +"/"+ url;
            String resoult=url;
            return resoult;
        } catch (Exception e) {
            return null;
        }
    }

}
